#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const ll N = 2e5 + 10, INF = 0x3f3f3f3f;

ll n, m, l, r;
struct node { ll u, v, w; };

bool cmp(node a, node b) { return a.w < b.w; }

struct DSU {
    std::vector<ll> f, sz;
    DSU() {}
    DSU(ll n) { init(n); }
    void init(ll n) {
        n++;
        f.resize(n);
        std::iota(f.begin(), f.end(), 0);
        sz.assign(n, 1);
    }
    ll find(ll x) {
        while (x != f[x]) {
            x = f[x] = f[f[x]];
        }
        return x;
    }
    ll size(ll x) {
        return sz[find(x)];
    }
    bool merge(ll x, ll y) {
        x = find(x);
        y = find(y);
        if (x == y) return false;
        sz[x] += sz[y];
        f[y] = x;
        return true;
    }
    bool same(ll x, ll y) {
        return find(x) == find(y);
    }
};

void solve()
{
    while (cin >> n >> m >> l >> r) {
        vector<node> p1, p2;
        DSU dsu1(n), dsu2(n);
        for (ll i = 0;i < m;i++) {
            ll u, v, a, b;
            cin >> u >> v >> a >> b;
            p1.push_back({ u,v,a + l * b });
            p2.push_back({ u,v,a + r * b });
        }
        sort(p1.begin(), p1.end(), cmp);
        sort(p2.begin(), p2.end(), cmp);

        ll ans1 = 0;
        for (ll i = 0;i < m;i++) {
            auto [u, v, w] = p1[i];
            if (dsu1.same(u, v) == 0) {
                ans1 += w;
                dsu1.merge(u, v);
            }
        }
        ll ans2 = 0;
        for (ll i = 0;i < m;i++) {
            auto [u, v, w] = p2[i];
            if (dsu2.same(u, v) == 0) {
                ans2 += w;
                dsu2.merge(u, v);
            }
        }
        cout << min(ans1, ans2) << '\n';
    }
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll T = 1;
    // cin >> T;
    for (ll i = 1;i <= T;i++) {
        solve();
    }
}